<template>
  <div id="bacHistories">
    <vxe-toolbar class-name="bg-grey light">
      <template #buttons>
        <span class="padding-lr-xs">历史回顾</span>
        <div>
          <vxe-radio-group v-model="formData.val1" @change="findBacHistories">
            <vxe-radio class="padding-lr-xs" label="1">所有</vxe-radio>
            <vxe-radio class="padding-lr-xs" label="2" size="medium">阳性</vxe-radio>
            <vxe-radio class="padding-lr-xs" label="3" size="small">阴性</vxe-radio>
            <vxe-radio class="padding-lr-xs" label="4" size="mini">涂片</vxe-radio>
          </vxe-radio-group>
        </div>
        <span>【</span>
        <vxe-input style="width:40px" placeholder="" v-model="formData.val3" />
        <span>】</span>
        <span>天内结果</span>
        <!-- <el-carousel height="30px" style="width:20%;" direction="vertical" indicator-position="none" :interval="3000">
          <el-carousel-item class="flex justify-end"> -->
        <span v-if="(noChanneAntList.length + noChanneGermList.length) > 0"
          class="text-bold wjxmjg redClazz">未建项目结果:</span>
        <span v-if="(noChanneAntList.length + noChanneGermList.length) > 0" style="cursor:pointer"
          class="text-blue wjxmjg" @click="noChannelResultClick">{{ noChanneAntList.length + noChanneGermList.length
          }}</span>
        <!-- </el-carousel-item>
        </el-carousel> -->
      </template>
    </vxe-toolbar>
    <div class="flex justify-start" style="height:100%">
      <div>
        <vxe-radio-group v-model="formData.val2" @change="findBacHistories">
          <div><vxe-radio class="padding-lr-xs" label="1" content="所有标本"></vxe-radio></div>
          <div><vxe-radio class="padding-lr-xs" label="2" content="同类标本"></vxe-radio></div>
          <div><vxe-radio class="padding-lr-xs" label="3" content="相同标本"></vxe-radio></div>
          <div><vxe-radio class="padding-lr-xs" label="4" content="同天标本"></vxe-radio></div>
          <div><vxe-radio class="padding-lr-xs" label="5" content="感染指标"></vxe-radio></div>
          <div><vxe-radio class="padding-lr-xs" label="6" content="相关检验"></vxe-radio></div>
        </vxe-radio-group>
      </div>
      <div style="height:calc(100% - 25px);overflow-y: auto;">
        <vxe-table ref="bacDrugTestResultRef" v-if="showBacTable" height="auto" :loading="labRptResultLoading" border
          show-overflow :data="bacDrugTestResult" :row-config="{ isCurrent: true }" :column-config="{ resizable: true }"
          :edit-config="{ trigger: 'click', mode: 'cell', showIcon: false }" @cell-dblclick="handleCellDblclick">
          <vxe-column type="seq" width="30"></vxe-column>
          <!--          <vxe-column field="isReport" title="状态" align="center" :edit-render="{}" width="60">
            <template #edit="{ row }">
              <vxe-checkbox v-model="row.isReport" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
            </template>
            <template #default="{ row }">
              <vxe-checkbox v-model="row.isReport" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
            </template>
          </vxe-column>-->
          <vxe-column field="sampleda" title="检验日期" min-width="120px">
            <template #default="{ row }">
              <span>{{ formatDateTime(row.sampleda, 'yyyy-MM-dd') }}</span>
            </template>
          </vxe-column>
          <vxe-column field="germNa" title="结果" width="100">
            <template #default="{ row }">
              <span v-if="formData.val1 == 4">{{ row.stainingMethNa
                + row.stainingConcNa + (row.stainingConcOptNa ? row.stainingConcOptNa : "") }}</span>
              <span v-else>{{ row.germNa }}</span>
            </template>

          </vxe-column>
          <vxe-column field="sampleNo" title="标本号" width="150"></vxe-column>
          <vxe-column field="traits" title="标本类型" width="150"></vxe-column>
          <vxe-column field="rptGroup" title="检验仪器" width="150"></vxe-column>
          <vxe-column field="reqPurpose" title="检验目的" width="150"></vxe-column>
          
          <vxe-column field="chkDoctor" title="审核人" width="150"></vxe-column>
          <vxe-column field="chkTime" title="审核时间" width="150">
            <template #default="{ row }">
              <span>{{ row.chkTime === null ? '' : formatDateTime(row.chkTime, 'yyyy-MM-dd') }}</span>
            </template>
          </vxe-column>
        </vxe-table>

        <vxe-table ref="bacDrugTestResultRef" v-if="!showBacTable" height="auto" :cell-style="calcCellBgColor"
          :loading="labRptResultLoading" border show-overflow :data="bacDrugTestResult" :row-config="{ isCurrent: true }"
          :column-config="{ resizable: true }" :edit-config="{ trigger: 'click', mode: 'cell', showIcon: false }">
          <vxe-column type="seq" width="30"></vxe-column>
          <vxe-column field="sampleda" title="检验日期" min-width="80px">
            <template #default="{ row }">
              <span>{{ formatDateTime(row.sampleda, 'yyyy-MM-dd') }}</span>
            </template>
          </vxe-column>
          <vxe-column field="sampleNo" title="标本号" width="70"></vxe-column>
          <vxe-column field="rptGroup" title="报告单元" width="100"></vxe-column>
          <vxe-column field="itemNa" title="检验项目" width="200"></vxe-column>
          <vxe-column field="testResult" title="检验结果" width="100"></vxe-column>
          <vxe-column field="resultFlag" title="" width="50">
            <template #default="{ row }">
              <span class="padding-lr-xs text-df">{{ getResultFlag(row.resultFlag) }}</span>
              <span class="padding-lr-xs" v-if="row.isAlarm === '1' || row.isAlarm === 1">{{ row.alarmText }}</span>
            </template>
          </vxe-column>
          <vxe-column field="ref" title="参考范围" width="150"></vxe-column>
        </vxe-table>

      </div>
    </div>
  </div>

  <!-- 通道号设置 -->
  <el-dialog title="对照设置" :show-close="false" v-model="showNoChannelResultDialog" append-to-body width="1000px"
    :close-on-click-modal="false" destroy-on-close v-if="showNoChannelResultDialog">
    <div class="tableBody" style="height: 600px">
      <Splitpanes horizontal class="horizontalLine">
        <Pane size="30">
          <vxe-table ref="noChannelTableRef" class="mytable-scrollbar dialogTable" border height="520px" align="center"
            :data="noChanneGermList">
            <vxe-column field="sampleNo" title="样本"></vxe-column>
            <vxe-column field="germMachineNo" title="仪器"></vxe-column>
            <vxe-column field="germNo" title="微生物代号"></vxe-column>
            <vxe-column field="result" title="结果"></vxe-column>
            <vxe-column field="germDictNo" title="微生物">
              <template #default="{ row }">
                <vxe-select v-model="row.germDictNo" :filterable="true" transfer clearable :disabled='resultIsDisabled()'>
                  <vxe-option v-for="bacGermDict in germDictList" :key="bacGermDict.germNo" :value="bacGermDict.germNo"
                    :label="bacGermDict.germNa + '(' + bacGermDict.germNo + ')'"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
          </vxe-table>

        </Pane>
        <Pane size="70">
          <vxe-table ref="noChannelTableRef" class="mytable-scrollbar dialogTable" border height="520px" align="center"
            :data="noChanneAntList">

            <vxe-column field="sampleNo" title="样本"></vxe-column>
            <vxe-column field="germMachineNo" title="仪器"></vxe-column>
            <vxe-column field="antCode" title="抗生素代号"></vxe-column>
            <vxe-column field="result" title="结果"></vxe-column>
            <vxe-column field="antDictNo" title="抗生素">
              <template #default="{ row }">
                <vxe-select v-model="row.antDictNo" :filterable="true" transfer clearable :disabled='resultIsDisabled()'>
                  <vxe-option v-for="bacAntDict in antDictList" :key="bacAntDict.antCode" :value="bacAntDict.antCode"
                    :label="bacAntDict.antName + '(' + bacAntDict.antCode + ')'"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
          </vxe-table>

        </Pane>
      </Splitpanes>
      <div class="dialog-footer flex right justify-end">
        <el-button type="primary" @click="saveBacthNoChannelResult('noChannelTableRef')"
          :disabled='resultIsDisabled()'>确定</el-button>
        <el-button @click="closeNoChannelResultDialog('noChannelTableRef')">取消</el-button>
      </div>
    </div>
  </el-dialog>

  <el-dialog title="药敏结果" :show-close="false" v-model="showDialog" append-to-body width="1000px"
    :close-on-click-modal="false" destroy-on-close v-if="showDialog">
    <div class="tableBody" style="height: 600px">
      <Splitpanes class="area">
        <Pane size="35">
          <vxe-table ref="methodTableRef" border align="left" class="mytable-scrollbar" resizable :loading="loading"
            height="auto" :data="methodTableData" :edit-config="{ trigger: 'click', mode: 'cell' }"
            :row-config="{ isCurrent: true }" :column-config="{ resizable: true }" show-overflow keep-source
            :scroll-y="{ enabled: true }">
            <vxe-column type="seq" title="#" width="30"></vxe-column>
            <vxe-column field="sampleda" title="检验日期"></vxe-column>
            <vxe-column field="germNa" title="结果"></vxe-column>
            <vxe-column field="sampleNo" title="标本号"></vxe-column>
            <vxe-column field="testPurpose" title="检验目的"></vxe-column>
          </vxe-table>
        </Pane>
        <Pane size="65">
          <vxe-table ref="drugRef" :column-config="{ resizable: true }" class="mytable-scrollbar dialogTable" border
            height="520px" align="center" :data="drugList" :loading="lloading"
            :checkbox-config="{ labelField: 'seq', highlight: true, checkAll: true }">
            <vxe-column type="checkbox" title="序号" width="70" tree-node></vxe-column>
            <vxe-column field="antNa" title="抗生素名称"></vxe-column>
            <vxe-column field="antNo" title="抗生素编号"></vxe-column>
            <vxe-column field="potency" title="效价" width="50"></vxe-column>
            <vxe-column field="drugTestMethNa" title="方法"></vxe-column>
            <vxe-column field="testResult" title="结果"></vxe-column>
            <vxe-column field="interpNa" title="敏感性"></vxe-column>
            <vxe-column field="breakPoint" title="折点"></vxe-column>
            <vxe-column field="germNo" title="微生物编码"></vxe-column>
          </vxe-table>
        </Pane>
      </Splitpanes>
      <div class="dialog-footer flex right justify-end">
        <el-button type="primary" @click="saveBacthDrug('drugRef')">确定</el-button>
        <el-button @click="closeDialog('drugRef')">取消</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive, getCurrentInstance, defineProps, onMounted } from 'vue';
import { formatDateTime, IsEmpty } from '@/utils/common';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import { Splitpanes, Pane } from 'splitpanes';
import { getOptionValueByCodeRptGroupOption, getOptionValueByCodeGlobalOption } from '@/utils/SysOptionsHelper';

defineExpose({
  init,
  initPage,
  findInstrGermResultInit,
  initGermObj
});

let { proxy }: any = getCurrentInstance();
const bacDrugTestResultRef = ref(null); /**药敏结果列表对象 */
const props = defineProps({
  tabs: {
    type: Array,
    default: reactive([
      {
        title: 'Step 1',
        iconSuccess: null,
        isValid: true
      },
      {
        title: 'Step 2',
        iconSuccess: null,
        isValid: true
      },
      {
        title: 'Step 3',
        iconSuccess: null,
        isValid: true
      }
    ])
  }
});
let layout: any[] = reactive([]); /**栅格布局数组 */
let formData: any = reactive({ val1: '', val2: '', val3: '', val4: '' }); /**菌落形态观察结果表单 */
let labMainInfoObj: any = reactive({}); /**检验记录当前选中对象 */
let bacDrugTestResult: any[] = reactive([]); /**细菌药敏检测结果 */
let form: any = reactive({
  autocalc: false
});
let activeName = ref('first');
let showBacTable = ref(true);
let labRptResultLoading = ref(false);

let showDialog = ref(false); //添加弹框展示状态
let lloading = ref(false); //弹框表格数据加载状态
let drugList: any = reactive([]); //弹框表格数据
let methodTableData: any = reactive([]); //弹框表格数据
let val1 = ref('');

function selectChangeEvent() {
  const $table = proxy.$refs.tableRef as VxeTableInstance<RowVO>
  const records = $table.getCheckboxRecords()
  console.info(`勾选${records.length}个树形节点`, records)
}


let germObj: any = reactive({}); /**当前选中的细菌 */

function initGermObj(germRow: any) {
  Object.assign(germObj, germRow);
}

/**初始化界面 */
function initPage(mainInfoRow: any) {
  Object.assign(labMainInfoObj, mainInfoRow);
  findBacHistories();
}

function init(mainInfoRow: any, val) {
  val1.value = val;
  Object.assign(labMainInfoObj, mainInfoRow);
  findBacHistories();
}


function findInstrGermResultInit(mainInfoRow: any) {
  findGermAndAntDictlList(mainInfoRow);
  findInstrGermResultNoChannelList(mainInfoRow);
}

function findBacHistories() {
  if (formData.val2 == 5) {
    showBacTable.value = false;
  } else {
    showBacTable.value = true;
  }
  bacDrugTestResult.length = 0;
  if (IsEmpty(labMainInfoObj.id)) {
    return;
  }
  labRptResultLoading.value = true;
  const url = '/api/bac/bac-test-result/findTestResultHistoryList';
  let data = { patNo: labMainInfoObj.patNo, rptGroup: labMainInfoObj.rptGroup, sampleType: labMainInfoObj.sampleType, sampleda: labMainInfoObj.sampleda + ' 00:00:00', val1: formData.val1, val2: formData.val2, val3: formData.val3 } as any;
  proxy.$http
    .get(url, { params: data })
    .then((res: any) => {
      labRptResultLoading.value = false;
      if (res && res.data && res.data.length >= 0) {
        bacDrugTestResult.push(...res.data);
        console.log('bacDrugTestResult', bacDrugTestResult);
        
      }
    })
    .catch((err: any) => {
      labRptResultLoading.value = false;
    });
}

let germDictList: any = reactive([]); //未维护通道号的结果列表
let antDictList: any = reactive([]); //未维护通道号的结果列表
let noChanneAntList: any = reactive([]); //未维护通道号的结果列表
let noChanneGermList: any = reactive([]); //未维护通道号的结果列表

function findGermAndAntDictlList(mainInfoRow: any) {
  germDictList.length = 0;
  antDictList.length = 0;

  //根据报告单元和日期 查出为对应得数据
  let url = '/int/instrGermResult/findGermAndAntDictlList';
  let obj = { rptGroup: mainInfoRow.rptGroup, sampleDaStr: mainInfoRow.sampleda, sampleNo: mainInfoRow.sampleNo };
  proxy.$http
    .get(url, { params: obj })
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage('获取未对应通道号失败', VxeNotifyType.error);
      } else {
        if (res.data.germDictList) {
          germDictList.push(...res.data.germDictList);
        }
        if (res.data.antDictList) {
          antDictList.push(...res.data.antDictList);
        }
      }
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}

function findInstrGermResultNoChannelList(mainInfoRow: any) {
  noChanneAntList.length = 0;
  noChanneGermList.length = 0;
  if (IsEmpty(mainInfoRow.rptGroup) || IsEmpty(mainInfoRow.sampleda) || IsEmpty(mainInfoRow.sampleNo)) {
    return;
  }
  //根据报告单元和日期 查出为对应得数据
  let url = '/int/instrGermResult/findInstrGermResultNoChannelList';
  let obj = { rptGroup: mainInfoRow.rptGroup, sampleDaStr: mainInfoRow.sampleda, sampleNo: mainInfoRow.sampleNo };
  proxy.$http
    .get(url, { params: obj })
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage('获取未对应通道号失败', VxeNotifyType.error);
      } else {
        if (res.data.noChanneAntList) {
          noChanneAntList.push(...res.data.noChanneAntList);
        }
        if (res.data.noChanneGermList) {
          noChanneGermList.push(...res.data.noChanneGermList);
        }
      }
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}

let showNoChannelResultDialog = ref(false); //中间质控靶值设定弹框展示状态

function noChannelResultClick() {
  showNoChannelResultDialog.value = true;
}

function closeNoChannelResultDialog() {
  showNoChannelResultDialog.value = false;
  //materialTargetList.length = 0;
}

function saveBacthNoChannelResult() {
  //取出所有itemDictId不为空得数据
  const germResultList = noChanneGermList.filter((p: any) => !IsEmpty(p.germDictNo));
  const antResultList = noChanneAntList.filter((p: any) => !IsEmpty(p.antDictNo));

  if (germResultList.length > 0 || antResultList.length > 0) {
    const data = {
      noChanneGermResultlList: germResultList,
      noChanneAntResultlList: antResultList
    };
    const url = '/int/instrGermResult/saveBacthGermNoChannelResult';
    proxy.$http
      .post(url, data)
      .then((res: any) => {
        showNoChannelResultDialog.value = false;
        findInstrGermResultNoChannelList(labMainInfoObj); // 获取检验仪器表格数据
        VxeMessage(res.status.msg, VxeNotifyType.success);
      })
      .catch((err: any) => {
        showNoChannelResultDialog.value = false;
        VxeMessage(err, VxeNotifyType.error);
      });
  } else {
    VxeMessage('请选择报告项目', VxeNotifyType.error);
  }
}
/**判断是否审核，若审核范围ture */
function resultIsDisabled() {
  if (!IsEmpty(labMainInfoObj) && labMainInfoObj.isChk == '2') {
    return true;
  } else {
    return false;
  }
}

/**
 * 单元格背景颜色
 *【1】是否启用系统选项颜色配置  encolorsetting
 *【2】偏高结果颜色  hresultcolor
 *【3】偏低结果颜色  lresultcolor
 *【4】阳性结果颜色  presultcolor
 *【5】正常结果颜色  mresultcolor
 *【6】弱阳性结果颜包  qresultcolor
 *【7】错误结果颜色  errresultcolor
 *【8】阴性结果颜色  nresultcolor
 *【9】结果标志颜色显示方式 jgbzysxsfs (0:背景色  1:文字颜色)
 */
function calcCellBgColor({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex }) {
  /**偏高【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'H' && column && column.field === 'resultFlag') {
    //查询系统选项偏高显示颜色   背景色还是文字颜色
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('hresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#ff0000' };
  }
  /**偏高【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'H' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('hresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#ff0000', color: '#fff' };
  }

  /**偏低【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'L' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('lresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ff' };
  }
  /**偏低【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'L' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('lresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ff', color: '#fff' };
  }

  /**阳性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'P' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('presultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ff' };
  }
  /**阳性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'P' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('presultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ff', color: '#fff' };
  }

  /**弱阳性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'Q' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('qresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ee' };
  }
  /**弱阳性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'Q' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('qresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ee', color: '#fff' };
  }

  /**错误【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'E' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('errresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#800000' };
  }
  /**错误【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'E' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('errresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#800000', color: '#fff' };
  }

  /**正常【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'M' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('mresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#000' };
  }
  /**正常【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'M' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('mresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { color: '#000' };
  }

  /**阴性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'N' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('nresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#000' };
  }
  /**阴性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'N' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('nresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { color: '#000' };
  }

  /**危急值 颜色 */
  if (row && !IsEmpty(row.isAlarm) && row.isAlarm === 1 && column && column.field === 'itemNo') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    const b = getOptionValueByCodeGlobalOption('isalarmcolor');
    const d = getOptionValueByCodeGlobalOption('wjzyssfxswbjys'); /**危急值颜色显示是否为背景颜色 wjzyssfxswbjys */
    if (a === 1 || a === '1') {
      if (!IsEmpty(b)) {
        if (d && (d === '1' || d === 1)) {
          return { background: b, color: '#fff' };
        } else {
          return { color: b };
        }
      }
    }
  }
}
function getResultFlag(val) {
  const a = getOptionValueByCodeRptGroupOption('zjmaccsxs');
  if (a === '1' || a === 1) {
    if (val === 'H') {
      const b = getOptionValueByCodeRptGroupOption('pgjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '↑';
    }
    if (val === 'L') {
      const b = getOptionValueByCodeRptGroupOption('pdjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '↓';
    }
    if (val === 'P') {
      const b = getOptionValueByCodeRptGroupOption('yxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '+';
    }
    if (val === 'Q') {
      const b = getOptionValueByCodeRptGroupOption('ryxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '±';
    }
    if (val === 'M') {
      const b = getOptionValueByCodeRptGroupOption('zcjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '';
    }
    if (val === 'E') {
      const b = getOptionValueByCodeRptGroupOption('cwjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '×';
    }
    if (val === 'N') {
      const b = getOptionValueByCodeRptGroupOption('nxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '√';
    }
  }
  if (val === 'H') {
    return '↑';
  }
  if (val === 'L') {
    return '↓';
  }
  if (val === 'P') {
    return '+';
  }
  if (val === 'Q') {
    return '±';
  }
  if (val === 'N') {
    return '√';
  }
  if (val === 'E') {
    return '×';
  }
  if (val === 'M') {
    return '';
  }
  return '';
}

function handleCellDblclick({ row, column }: any) {
  console.log('val1', val1, labMainInfoObj,row);

  //判断row的GermNo是否为空
  if (IsEmpty(row.germNo)) {
    return;
  }
  if (row.labMainInfoObj == 2) {
    return;
  }
  if (val1.value == 'result') {

    
    methodTableData.length = 0;
    methodTableData.push(row);

    let data = { rptGroup: row.rptGroup, sampleda: row.sampleda + ' 00:00:00', sampleNo: row.sampleNo, testFlowNo: row.testFlowNo, testNodeNo: row.testNodeNo, germNo: row.germNo, isolateNum: row.isolateNum } as any;

    drugList.length = 0; //放入数据前清空数据
    const url = '/api/bac/bac-test-result/findTestResultAndDrugList';
    proxy.$http
      //注意此处的数据条数
      .get(url, { params: data })
      .then(async (res: any) => {
        drugList.push(...res.data);
      })
      .catch((err: any) => {
        VxeMessage('获取药敏数据异常', VxeNotifyType.error);
      });

    showDialog.value = true;
  }
}

function closeDialog() {
  showDialog.value = false;
}

function saveBacthDrug() {
  const $table = proxy.$refs.drugRef as VxeTableInstance<RowVO>
  const records = $table.getCheckboxRecords();
  //判断methodTableData是否为空,取出methodTableData中的第一条数据
  if (methodTableData.length == 0) {
    VxeMessage('请先选择细菌', VxeNotifyType.error);
    return;
  }
  const germRow = methodTableData[0];

  const data = {
    bacTestResult: germRow,
    bacDrugTestResultList: records,
    labMaininfo: labMainInfoObj,
    germResult: germObj
  };

  console.log('data', data);

  const url = '/api/bac/bac-test-result/syncTestResultAndDrugList';
  proxy.$http
    .post(url, data)
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage(res.status.msg, VxeNotifyType.error)
      } else {
        //调用父组件的刷新方法
        proxy.$emit('retrieve');
        VxeMessage(res.status.msg, VxeNotifyType.success);
      }
      showDialog.value = false;
    })
    .catch((err: any) => {
      showDialog.value = false;
      VxeMessage(err, VxeNotifyType.error);
    });

}

</script>

<style scoped lang="scss">.bacHistories {
  height: 100%;

  .redClazz {
    color: red;
    margin-right: 10px;
  }

  .wjxmjg {
    font-size: 16px;
  }
}

:deep(.vxe-toolbar) {
  padding: 0.01em 0;
}</style>
